<?php

namespace App\Models\Admin\Authority;

class AuthorityButtonModel extends BaseAuthorityModel
{
    protected $table = 'authority_buttons';

    /**
     * 根据 authorityId 查询列表
     *
     * @param int   $authorityId
     * @param array $fields
     * @return array
     */
    public function getItemsByAuthorityId(int $authorityId, array $fields = self::QUERY_DEFAULT_FIELDS): array
    {
        return $this->select($fields)
            ->where('authority_id', $authorityId)
            ->get()
            ->toArray();
    }

    /**
     * 根据菜单id将数据标为删除
     *
     * @param int $menuId
     * @return int
     */
    public function deleteItemByMenuId(int $menuId): int
    {
        return $this->where('menu_id', $menuId)
            ->where('deleted', self::DELETED_NO)
            ->update([
                'deleted' => self::DELETED_YES,
            ]);
    }

    /**
     * 根据角色id将数据标记为删除
     *
     * @param int $authorityId
     * @return int
     */
    public function deleteItemByAuthorityId(int $authorityId): int
    {
        return $this->where('authority_id', $authorityId)
            ->delete();
    }
}
